package com.github.thinwonton.activemq.showcase.prefetch;

import com.github.thinwonton.activemq.showcase.ActiveMQManager;

import javax.jms.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Sender {

    public static void main(String[] args) throws JMSException, InterruptedException {
        Connection connection = ActiveMQManager.createConnection();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(Utils.QUEUE_NAME);
        MessageProducer producer = session.createProducer(queue);

        while (true) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
            for (int i = 0; i < 25; i++) {
                String date = dateFormat.format(new Date());
                String message = String.format("msg[%s][%s]", i, date);

                TextMessage toMessage = session.createTextMessage(message);
                producer.send(toMessage);
                System.out.println("消息发送成功：" + message);
            }

            Thread.sleep(30000); //10秒发送一批次
        }

    }
}
